<template></template>

<script lang="ts">
import { add, update } from '@/api/operation/alarmRule/index';
import common from '@/utils/common.ts';

export default {
  props: {
    data: {}
  },
  computed: {},
  data() {
    return {
      loading: false,
      placeType: [
        { label: '站房', value: '1' },
        { label: '酒店', value: '2' }
      ],
      deviceType: [],
      item: {}
    };
  },
  created() {
    this.init();
  },
  methods: {
    init(data) {
      if (data == null) this.item = this.data;
      else this.item = data;
    },

    handleCancel() {
      this.$emit('hideRight');
    },

    handleSave() {
      let data = this.item;
      if (data.planId == null) {
        //新增
        this.add();
      } else {
        //编辑
        this.update();
      }
    },

    add() {
      this.loading = true;
      add(this.item)
        .then((res) => {
          this.loading = false;
          if (res.code == 200) {
            this.$emit('hideRight');
          } else {
            ElMessage.error(res.msg);
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },

    update() {
      this.loading = true;
      update(this.item)
        .then((res) => {
          this.loading = false;
          if (res.code == 200) {
            this.$emit('hideRight');
          } else {
            ElMessage.error(res.msg);
          }
        })
        .catch(() => {
          this.loading = false;
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.main {
  height: 100%;
}
</style>